﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web.Mvc;
using Xenta.Attributes;
using Xenta.Utils;
using Xenta.Web.Controllers;

namespace Xenta.Web.Areas.Store.Controllers
{
    public sealed class SellerController : ExtController
    {
        #region GET/POST Actions

        [HttpGet, RestoreState]
        public ActionResult Show(int id)
        {
            dynamic m = Svc.ProcessOperation("GetSeller", new
            {
                EntityID = id
            }, new
            {
                DisclosureLevel = "Entire"
            });
            if(m == null)
                return HttpNotFound();
            return View(m);
        }

        #endregion

        #region Childs Actions

        [ChildActionOnly]
        public ActionResult _ItemList(int id)
        {
            dynamic m = new ExpandoObject();

            m.Seller = Svc.ProcessOperation("GetSeller", new
            {
                EntityID = id
            }, new
            {
                DisclosureLevel = "Base"
            });
            if(m.Seller == null)
                return HttpNotFound();

            m.Items = Svc.ProcessOperation("SearchSalesItemsOverCatalog", new
            {
                LanguageID = JDM.Int32(Svc.Localization.Language.EntityID),
                SellerID = id,
                Count = 12,
                CatalogFlagMask = "Active",
                SalesSortBy = new[] 
                {
                    "CreatedOn"
                },
                SortDir = "Descending"
            }, new
            {
                DisclosureLevel = "Extended",
                DisclosureOptions = new Dictionary<String, String>
                {
                    { "TranslatedTo", JDM.String(Svc.Localization.Language.Code) }
                }.Unload()
            });
            return PartialView(m);
        }

        [ChildActionOnly]
        public ActionResult _Overview(int id)
        {
            dynamic m = Svc.ProcessOperation("GetSeller", new
            {
                EntityID = id
            }, new
            {
                DisclosureLevel = "Entire"
            });
            return PartialView(m);
        }

        [ChildActionOnly]
        public ActionResult _Comments(int id)
        {
            dynamic m = new ExpandoObject();

            m.EntityID = id;
            m.Comments = Svc.ProcessOperation("SearchSellerComments", new
            {
                HolderID = id
            }, new
            {
                DisclosureLevel = "Extended"
            }).Items;
            return PartialView(m);
        }

        #endregion
    }
}
